<?
		$sql['order'] = "custom_sort, ".$sql['order'];
		
		
		if (strpos($sql['columns'], ",custom_sort") === FALSE) {
			$sql['columns'] .= ",custom_sort";
		} 
		if (strpos($sql['columns'], ",custom_dist") === FALSE) {
			$sql['columns'] .= ",custom_dist";
		} 
		
		$criteria = getOne("SELECT AVG(custom_dist) FROM p2.gridimage{$id}_bi WHERE custom_sort > 0");
		
		function searchbreak(&$c,$start='',$end='') {
			static $last;
			static $count;
			static $hidden;
			global $criteria;
			
			if (empty($c)) {//its the last one
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images)";
					}
				}
				return;
			}
			
			$dist = $c['custom_dist'];
			
			if ($dist > $criteria) {
			
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images)";
					}
				}

				print "<h4>&nbsp;</h4>";
				print $start;
				$count = 1;
				$hidden =0;
			} else {
				$count++;
				if ($count > 4) {
					$GLOBALS['opt']['has_hidden'] = true;
					$GLOBALS['resultCount']--;
					$hidden++;
					return false;
				}
			}
			
			$last = 1;
			return true; //we dont disable any images...
		}
		
		$opt['opt'] = 'linear';
